<template>
    <el-dialog :center="false" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true"
               :title="dialogTitle"
               top="20px" v-model="dialogTableVisible" width="80%">

        <el-form :model="ruleForm" :rules="rules" class="demo-ruleForm" ref="ruleForm">
            <el-form-item label="主键" prop="idResourcesSummary" v-if="false">
                <el-input clearable placeholder="请输入主键"
                          v-model="ruleForm.idResourcesSummary"></el-input>
            </el-form-item>
            <el-form-item label="修改人" prop="updatedBy"
                          v-if="!true">
                <el-input clearable placeholder="请输入修改人"
                          v-model="ruleForm.updatedBy"></el-input>
            </el-form-item>

            <el-form-item label="修改日期" prop="updatedDate"
                          v-if="!true">
                <el-date-picker clearable placeholder="请选择修改日期" type="date"
                                v-model="ruleForm.updatedDate">
                </el-date-picker>
            </el-form-item>

            <el-form-item label="创建人" prop="createdBy"
                          v-if="!true">
                <el-input clearable placeholder="请输入创建人"
                          v-model="ruleForm.createdBy"></el-input>
            </el-form-item>

            <el-form-item label="创建日期" prop="createdDate"
                          v-if="!true">
                <el-date-picker clearable placeholder="请选择创建日期" type="date"
                                v-model="ruleForm.createdDate">
                </el-date-picker>
            </el-form-item>

            <el-form-item label="是否删除 1 是 0否" prop="isDel"
                          v-if="!true">
                <el-input-number clearable placeholder="请输入是否删除 1 是 0否"
                                 v-model="ruleForm.isDel"/>
            </el-form-item>

            <el-form-item label="状态名称" prop="statusName"
                          v-if="!true">
                <el-input clearable placeholder="请输入状态名称"
                          v-model="ruleForm.statusName"></el-input>
            </el-form-item>
            <el-form-item label="系统编号" prop="dataNo"
                          v-if="!true">
                <el-input clearable placeholder="请输入系统编号"
                          v-model="ruleForm.dataNo"></el-input>
            </el-form-item>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="系统信息" prop="informationsSingleId"
                                  required v-if="!false">
                        <el-select @change="loadMenus"
                                   clearable
                                   filterable
                                   :disabled="readonly"
                                   placeholder="请选择系统信息"
                                   v-model="ruleForm.informationsSingleId">
                            <el-option
                                    :key="sitem.idInformations"
                                    :label="sitem.sysName"
                                    :value="sitem.idInformations"
                                    v-for="sitem in informationsSingleIdList"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="菜单信息" prop="menusList"
                                  required v-if="!false">
                        <el-select @change="changeMenusName"
                                   clearable
                                   multiple
                                   filterable
                                   collapse-tags
                                   placeholder="请选择菜单"
                                   v-model="ruleForm.menusList">
                            <el-option
                                    :key="sitem.idMenusinfo"
                                    :label="sitem.menuName"
                                    :value="sitem.idMenusinfo"
                                    v-for="sitem in menuPathList"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="12">
                    <el-form-item label="角色信息" prop="rolesList"
                                  required v-if="!false">
                        <el-select @change="changeMenusName"
                                   clearable
                                   multiple
                                   filterable
                                   collapse-tags
                                   placeholder="请选择角色"
                                   v-model="ruleForm.rolesList">
                            <el-option
                                    :key="sitem.idRolesinfo"
                                    :label="sitem.roleName"
                                    :value="sitem.idRolesinfo"
                                    v-for="sitem in rolesList"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="状态编码" prop="statusCode"
                                  required v-if="!false">
                        <el-select placeholder="请选择状态编码" v-model="ruleForm.statusCode">
                            <el-option
                                    :key="sitem.statusCode"
                                    :label="sitem.statusName"
                                    :value="sitem.statusCode"
                                    clearable
                                    v-for="sitem in selectData"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="描述" prop="remark"
                                  v-if="!false">
                        <el-input
                                v-model="ruleForm.remark"
                                maxlength="1000"
                                placeholder="请输入描述"
                                show-word-limit
                                type="textarea"
                        />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="margin-bottom: 5px;">
                <el-col :span="6">
                    <el-button @click="handleAddDetails" size="mini" type="primary">
                        <font-awesome-icon icon="plus-circle" style="color:#e3e9f2;"/>
                        添加
                    </el-button>
                    <el-button @click="handleDeleteAllDetails" size="mini" type="danger">
                        <font-awesome-icon icon="trash-alt" style="color:#e3e9f2;"/>
                        清空
                    </el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-table
                            :data="ruleForm.resourcesPos"
                            :row-class-name="rowClassName"
                            @selection-change="handleDetailSelectionChange"
                            border
                            fit="true"
                            ref="tb"

                    >
                        <!-- <el-table-column align="center" type="selection" width="30"/>
                         <el-table-column align="center" label="序号" prop="xh" width="50"></el-table-column>-->
                        <el-table-column
                                :formatter="dataFormat"
                                :show-overflow-tooltip="true"
                                label="资源名称"
                                prop="resName"
                                required v-if="true ">
                            <template #default="scope">
                                <el-form-item required :prop="'resourcesPos.'+scope.$index+'.resName'">
                                    <el-input clearable placeholder="请输入资源名称"
                                              v-model="scope.row.resName"></el-input>
                                </el-form-item>

                            </template>
                        </el-table-column>
                        <el-table-column
                                :formatter="dataFormat"
                                :show-overflow-tooltip="true"
                                label="资源编码"
                                prop="resCode"
                                required v-if="true ">
                            <template #default="scope">
                                <el-form-item required :prop="'resourcesPos.'+scope.$index+'.resCode'">
                                    <el-input clearable placeholder="请输入资源编码"
                                              v-model="scope.row.resCode"
                                              required></el-input>
                                </el-form-item>
                            </template>
                        </el-table-column>
                        <el-table-column
                                :formatter="dataFormat"
                                :show-overflow-tooltip="true"
                                label="操作"
                                width="100"
                                prop="resCode"
                                required v-if="true ">
                            <template #default="scope">
                                <el-button @click="handleDeleteDetails(scope.$index)" size="mini" type="danger">
                                    <font-awesome-icon icon="trash" style="color:#e3e9f2;"/>
                                    删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <table>
                        <tr>
                            <td>
                                <el-button @click="merge()" size="small" type="primary">
                                    <font-awesome-icon icon="save" style="vertical-align: middle;color:#e3e9f2;"/>
                                    <span style="vertical-align: middle;">  提交 </span></el-button>
                            </td>
                            <td>
                                <el-button @click="mergeDraft()" size="small" type="primary">
                                    <font-awesome-icon icon="save" style="vertical-align: middle;color:#e3e9f2;"/>
                                    <span style="vertical-align: middle;">  暂存 </span></el-button>
                            </td>
                            <td>
                                <el-button @click="resetForm()" size="small">
                                    <font-awesome-icon icon="undo" style="vertical-align: middle;color:#e3e9f2;"/>
                                    <span style="vertical-align: middle;">  重置 </span></el-button>
                            </td>
                        </tr>
                    </table>
                </el-col>
            </el-row>
        </el-form>
    </el-dialog>
    <el-dialog :center="false" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true"
               title="查看数据"
               top="20px" v-model="viewVisible" width="80%">
        <el-form :model="ruleForm" class="view-ruleForm" label-width="15%" ref="ruleForm">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="系统信息" prop="informationsPo">
                        <span>{{ruleForm.informationsPo.sysName}}</span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="菜单信息" prop="menusList">
                    <span>
                        <template v-for="item in ruleForm.menusList">
                        {{item.menuName}},
                    </template> </span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="角色信息" prop="rolesList">
                        <span>
                        <template v-for="item in ruleForm.rolesList">
                        {{item.roleName}},
                    </template> </span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="状态" prop="idMenusinfo">
                        <span>{{ruleForm.statusName}}</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="text-align: left">
                <el-col :span="12">
                    <el-form-item label="描述" prop="remark">
                        <span>{{ruleForm.remark}}</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-table
                        :data="ruleForm.resourcesPos"
                        :row-class-name="rowClassName"
                        border
                        fit="true"
                        ref="tb"
                >
                    <el-table-column
                            :formatter="dataFormat"
                            :show-overflow-tooltip="true"
                            label="资源名称"
                            prop="resName"
                            required v-if="true ">

                    </el-table-column>
                    <el-table-column
                            :formatter="dataFormat"
                            :show-overflow-tooltip="true"
                            label="资源编码"
                            prop="resCode"
                            required v-if="true ">
                    </el-table-column>
                </el-table>
            </el-row>
            <el-row>
                <el-col>
                    <el-button @click="this.viewVisible=!this.viewVisible" size="small" type="warning">关闭</el-button>
                </el-col>
            </el-row>
        </el-form>
    </el-dialog>
    <div style="height: 100%">
        <!--查询区域-->
        <table class="inner_button">
            <tr>
                <td v-if="permission.add">
                    <el-button @click="btnOperation(1)" size="small" type="primary">
                        <font-awesome-icon icon="plus" style="vertical-align: middle;color:#e3e9f2;"/>
                        <span style="vertical-align: middle;"> 新增 </span>
                    </el-button>
                </td>
                <!--     <td v-if="permission.batchAdd">
                         <el-button @click="btnOperation(11)" size="small" type="primary">
                             <font-awesome-icon icon="plus-square" style="vertical-align: middle;color:#e3e9f2;"/>
                             <span style="vertical-align: middle;"> 批量新增 </span>
                         </el-button>
                     </td>-->
                <td v-if="permission.edit">
                    <el-button @click="btnOperation(2)" size="small" type="primary">
                        <font-awesome-icon icon="edit" style="vertical-align: middle;color:#e3e9f2;"/>
                        <span style="vertical-align: middle;">  编辑 </span>
                    </el-button>
                </td>
                <td v-if="permission.view">
                    <el-button @click="btnOperation(3)" size="small" type="primary">
                        <font-awesome-icon icon="book-open" style="vertical-align: middle;color:#e3e9f2;"/>
                        <span style="vertical-align: middle;">  查看 </span>
                    </el-button>
                </td>
                <td v-if="permission.delete">
                    <el-button @click="btnOperation(4)" size="small" type="danger">
                        <font-awesome-icon icon="minus-square" style="vertical-align: middle;color:#e3e9f2;"/>
                        <span style="vertical-align: middle;">  删除 </span>
                    </el-button>
                </td>
                <td v-if="permission.view">
                    <el-button @click="btnOperation(5)" size="small" type="primary">
                        <font-awesome-icon icon="sync" style="vertical-align: middle;color:#e3e9f2;"/>
                        <span style="vertical-align: middle;">  刷新 </span>
                    </el-button>
                </td>
                <!--   <td v-if="permission.download">
                       <el-button @click="btnOperation(6)" size="small" type="primary">
                           <font-awesome-icon icon="file-download" style="vertical-align: middle;color:#e3e9f2;"/>
                           <span style="vertical-align: middle;">  下载模板 </span>
                       </el-button>
                   </td>
                   <td v-if="permission.execution">
                       <el-button @click="btnOperation(7)" size="small" type="primary">
                           <font-awesome-icon icon="play-circle" style="vertical-align: middle;color:#e3e9f2;"/>
                           <span style="vertical-align: middle;">  执行 </span>
                       </el-button>
                   </td>
                   <td v-if="permission.upload">
                       <el-upload
                               :auto-upload="true"
                               :on-change="upload"
                               :on-error="uploadError"
                               :on-progress="uploadProcess"
                               :on-success="uploadSuccess"
                               :show-file-list="false"
                               action="/system-config/system/resourcesEntity/importData"
                               class="upload-demo"
                               name="file"
                       >
                           <el-button size="small" type="primary">
                               <font-awesome-icon icon="file-upload" style="vertical-align: middle;color:#e3e9f2;"/>
                               <span style="vertical-align: middle;">  上传 </span></el-button>
                       </el-upload>
                   </td>
                   <td v-if="permission.export">
                       <el-button @click="btnOperation(8)" size="small" type="primary">
                           <font-awesome-icon icon="file-export" style="vertical-align: middle;color:#e3e9f2;"/>
                           <span style="vertical-align: middle;">  导出 </span>
                       </el-button>
                   </td>-->
            </tr>
        </table>

        <el-table
                :data="dataList"
                :row-key="getRowIdentity"
                @row-dblclick="editData"
                @selection-change="handleSelectionChange"
                border
                fit="true"
                highlight-current-row="true"
                id="resourcesPo"
                ref="multipleTable"
                stripe="true"
                style="width: 100%;height:81%">
            <el-table-column fixed width="1"/>
            <el-table-column
                    :reserve-selection="true"
                    align="center"
                    type="selection"
            />
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="主键"
                    prop="idResourcesSummary"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="系统名称"
                    prop="informationsSingleId"
                    v-if="true ">
            </el-table-column>

            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="修改人"
                    prop="updatedBy"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="修改日期"
                    prop="updatedDate"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="创建人"
                    prop="createdBy"
                    v-if=" true ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="创建日期"
                    prop="createdDate"
                    v-if=" true ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="是否删除 1 是 0否"
                    prop="isDel"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="状态名称"
                    prop="statusName"
                    v-if="true ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="状态编码"
                    prop="statusCode"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="系统编号"
                    prop="dataNo"
                    v-if=" false ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="角色名称"
                    prop="rolesList"
                    v-if="true ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="菜单名称"
                    prop="menusList"
                    v-if="true ">
            </el-table-column>
            <el-table-column
                    :formatter="dataFormat"
                    :show-overflow-tooltip="true"
                    label="权限"
                    prop="resourcesPos"
                    v-if="true ">
            </el-table-column>
        </el-table>
        <el-pagination
                :current-page="currentPage"
                :page-count="totalPage"
                :page-size="pageSize"
                :page-sizes="[20,50, 100, 150, 200]"
                :total="totalData"
                @current-change="pageChangeClick"
                @next-click="pageClick(2)"
                @prev-click="pageClick(1)"
                @size-change="pageSizeClick"
                current-page="当前页"
                jumper-text="跳转"
                layout="total, sizes, prev, pager, next, jumper"
                next-text="下一页"
                prev-text="上一页">
        </el-pagination>
    </div>
</template>
<style>

</style>
<script>
    import {ElLoading} from "element-plus"
    import {confirm, error, success, warning} from "../../utils/message";
    import {
        download,
        getRequest,
        loadConfigedMenus,
        loadDepartments,
        loadRoleDatas,
        permissionResources,
        postRequest
    } from "../../api/star_horse";

    export default {
        name: "ResourcesEntity",
        setup() {
            return {}
        },
        data() {
            return {
                loading: null,
                batchDialogTitle: "",
                batchDialogTableVisible: false,
                dialogTableVisible: false,
                uploadVisible: false,
                viewVisible: false,
                readonly: false,
                dialogTitle: "",
                baseresourcesPos: [
                    {
                        resName: "新增",
                        resCode: "add"
                    },
                    {
                        resName: "批量新增",
                        resCode: "batchAdd"
                    },
                    {
                        resName: "编辑",
                        resCode: "edit"
                    },
                    {
                        resName: "查看",
                        resCode: "view"
                    },
                    {
                        resName: "删除",
                        resCode: "delete"
                    },
                    {
                        resName: "下载",
                        resCode: "download"
                    },
                    {
                        resName: "执行",
                        resCode: "execution"
                    },
                    {
                        resName: "上传",
                        resCode: "upload"
                    }, {
                        resName: "导出",
                        resCode: "export"
                    }
                ],
                ruleForm: {},
                dataList: [],
                permission: {view: "view", add: "add",export:"export",upload:"upload",download:"download",delete:"delete"},
                informationsSingleIdList: [],
                checkedDetail: [],

                rolesList: [],
                selectData: [],
                currentPage: 1,
                pageSize: 20,
                totalPage: 0,
                totalData: 0,
                rules: {}
            }
        },
        methods: {
            /**
             * 根据系统加载菜单
             * */
            loadMenus() {
                let that = this;
                let query = [];
                this.ruleForm["menuNames"] = [];
                query.push({
                    "propertyName": "informationsSingleId",
                    "value": that.ruleForm.informationsSingleId
                })
                loadConfigedMenus(query).then(res => {
                    let redata = res.data;
                    that.menuPathList = redata.data;
                }).catch(err => {
                    error(err);
                });

            },
            rowClassName({row, rowIndex}) {
                row.xh = rowIndex + 1;
            },
            //单选框选中数据
            handleDetailSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.tb.clearSelection();
                    this.$refs.tb.toggleRowSelection(selection.pop());
                } else {
                    this.checkedDetail = selection;
                }
            },
            handleAddDetails() {
                if (this.ruleForm.resourcesPos == undefined) {
                    this.ruleForm.resourcesPos = new Array();
                }
                let obj = {};
                obj.idResourcesSummary = "";
                obj.idMenusinfo = "";
                obj.resName = "";
                obj.resCode = "";
                obj.updatedBy = "";
                obj.updatedDate = "";
                obj.createdBy = "";
                obj.createdDate = "";
                obj.isDel = "";
                obj.statusName = "";
                obj.statusCode = "";
                obj.dataNo = "";
                this.ruleForm.resourcesPos.push(obj);
            },
            handleDeleteDetails(index) {
                this.ruleForm.resourcesPos.splice(index, 1);
            },
            handleDeleteAllDetails() {
                let that = this;
                confirm("确定要清空所有资源数据吗?", function () {
                    that.ruleForm.resourcesPos = [];
                })

            },
            dataFormat(row, column, cellValue, index) {
                if (!cellValue) {
                    return "-";
                }
                let names = [];
                if (column.property == "rolesList") {
                    row.rolesList.forEach(item => names.push(item.roleName));
                    return names.toLocaleString();
                }
                if (column.property == "menusList") {
                    row.menusList.forEach(item => names.push(item.menuName));
                    return names.toLocaleString();
                }
                if (column.property == "informationsSingleId") {
                    return row.informationsPo.sysName;
                }
                if (column.property == "resourcesPos") {
                    row.resourcesPos.forEach(item => names.push(item.resName));
                    return names.toLocaleString();
                }
                if (column.property == "createdDate" || column.property == "updatedDate") {
                    let date = new Date(cellValue);
                    return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
                } else {
                    return cellValue;
                }
            },
            /**
             * 加载框
             */
            load(msg) {
                if (!this.loading) {
                    this.loading = ElLoading.service({
                        lock: true,
                        target: "#resourcesPo",
                        text: msg || 'Loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    });
                } else {
                    this.loading.open();
                }
            }
            ,
            closeLoad() {
                if (this.loading) {
                    this.loading.close();
                    this.loading = null;
                }
            }
            ,
            getRowIdentity(row) {
                return row[this.getIdName()];
            }
            ,
            getIdName() {
                return "idResourcesSummary";
            },
            /**
             * 按钮操作
             */
            btnOperation(type) {
                this.closeLoad();
                switch (type) {
                    //新增编辑
                    case 1:
                        this.ruleForm = {};
                        this.readonly = false;
                        this.dialogTableVisible = !this.dialogTableVisible;
                        this.dialogTitle = "新增数据";
                        this.ruleForm.resourcesPos = this.baseresourcesPos;
                        break;
                    case 11:
                        this.readonly = false;
                        this.ruleForm.resourcesPos = [];
                        this.batchDialogTableVisible = !this.batchDialogTableVisible;
                        this.batchDialogTitle = "批量新增";
                        break;
                    case 2:
                        this.ruleForm = {};
                        if (!this.multipleSelection || this.multipleSelection.length != 1) {
                            warning("请选择一条要编辑的数据");
                            return;
                        }

                        this.ruleForm["informationsSingleId"] = this.multipleSelection[0]["informationsSingleId"];
                        //数据会有延迟问题,暂时不做处理
                        this.loadMenus();
                        this.loadById(this.multipleSelection[0][this.getIdName()]);
                        this.dialogTableVisible = !this.dialogTableVisible;
                        this.dialogTitle = "编辑数据";
                        this.readonly = true;
                        // this.$refs.multipleTable.clearSelection();
                        break;
                    //查看
                    case 3:
                        if (this.multipleSelection.length != 1) {
                            warning("查看数据只能选择一条");
                            return;
                        }
                        this.loadById(this.multipleSelection[0][this.getIdName()], true);
                        break;
                    //删除
                    case 4:
                        this.delete()
                        break;
                    //刷新
                    case 5:
                        this.refresh();
                        break;
                    //下载模板
                    case 6:
                        this.downloadTemplate();
                        break;
                    //导出
                    case 8:
                        this.exportAll();
                        break;
                    default:
                        throw error("未知类型");
                }
            }
            ,
            pageClick(type) {
                this.loadByPage(this.currentPage, this.pageSize);
            }
            ,
            pageSizeClick(pageSize) {
                this.pageSize = pageSize;
                this.loadByPage(this.currentPage, pageSize);
            }
            ,
            pageChangeClick(currentPage) {
                this.currentPage = currentPage;
                this.loadByPage(this.currentPage, this.pageSize);
            }
            ,
            editData(row, column, event) {
                this.loadById(row[this.getIdName()], true);

            }
            ,
            //重置数据
            resetForm() {
                this.ruleForm = {};
                this.resourcesPos = [];
            }
            ,
            //处理选中的数据
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
            ,
            /**
             * 初始化数据
             */
            init: function () {
                this.dataList = [];
                this.selectData = [];
                this.loadByPage(this.currentPage, this.pageSize);
                this.loadPermissionResources();
                this.loadSelectData();
                this.informationsSingleIdListFun();
                this.loadRolesData();

            },
            loadRolesData() {
                let that = this;
                let query = [];
                loadRoleDatas(query).then(res => {
                    that.rolesList = res;
                }).catch(err => {
                    error(err);
                });
            },
            /**
             * 系统信息
             */
            informationsSingleIdListFun() {
                let that = this;
                let query = [];
                loadDepartments(query).then(res => {
                    that.informationsSingleIdList = res;
                }).catch(err => {
                    error(err);
                });
            }
            ,
            /**
             * 加载资源权限
             */
            loadPermissionResources() {
                let that = this;
                let meta = that.$router.currentRoute.value.meta;
                let data = {"menuId": meta.menuId};
                permissionResources(data).then(res => {
                    let redata = res.data.data;
                    redata.forEach(item => {
                        that.permission[item.resCode] = item.resCode;
                    });
                });
            },
            /**
             * 状态码数据
             */
            loadSelectData() {
                let that = this;
                let query = [];
                query.push({
                    "propertyName": "statusType",
                    "value": "sys_resources"
                })
                postRequest("/system-config/system/statusinfoEntity/getAllByCondition", query).then(res => {
                    let redata = res.data;
                    that.selectData = redata.data;
                }).catch(err => {
                    error(err);
                });
            }
            ,
            /**
             * 分页显示数据
             */
            loadByPage: function (currentPage, pageSize) {
                let that = this;
                this.load();
                postRequest("/system-config/system/resourcesSummaryEntity/pageList", {
                    currentPage: currentPage < 1 ? 1 : currentPage,
                    pageSize: pageSize || that.pageSize
                }).then(res => {
                    let redata = res.data.data;
                    that.dataList = redata.dataList;
                    that.totalPage = redata.totalPages;
                    that.currentPage = redata.currentPage;
                    that.totalData = redata.totalDatas;
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 刷新数据
             */
            refresh: function () {
                this.init();
            }
            ,
            /**
             * 编辑保存数据
             */
            merge: function () {
                let flag = false;
                let that = this;
                that.$refs.ruleForm.validate((valid) => {
                    flag = valid;
                });
                if (!flag) {
                    return;
                }
                that.load();
                let statusCode = that.ruleForm.statusCode;
                if (statusCode && that.selectData && that.selectData.length > 0) {
                    let sData = that.selectData.find(item => item.statusCode === statusCode);
                    that.ruleForm.statusName = sData.statusName;
                }
                postRequest("/system-config/system/resourcesSummaryEntity/merge", that.ruleForm).then(res => {
                    success(res.data.cnMessage);
                    that.closeLoad();
                    that.loadByPage(1, that.pageSize);
                    that.ruleForm = {};
                    that.dialogTableVisible = !that.dialogTableVisible;
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 编辑保存数据
             */
            mergeDraft: function () {
                let that = this;
                this.load();
                let statusCode = that.ruleForm.statusCode;
                if (statusCode && that.selectData && that.selectData.length > 0) {
                    let sData = that.selectData.find(item => item.statusCode === statusCode);
                    that.ruleForm.statusName = sData.statusName;
                }
                postRequest("/system-config/system/resourcesSummaryEntity/mergeDraft", that.ruleForm).then(res => {
                    success(res.data.cnMessage);
                    that.closeLoad();
                    that.loadByPage(1, this.pageSize);
                    that.ruleForm = {};
                    that.dialogTableVisible = !that.dialogTableVisible;
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 批量编辑保存数据
             */
            batchMerge: function () {
                let that = this;
                this.load();
                postRequest("/system-config/system/resourcesSummaryEntity/mergeBatch", that.resourcesPos).then(res => {
                    success(res.data.cnMessage);
                    that.closeLoad();
                    that.loadByPage(1, this.pageSize);
                    that.resourcesPos = [];
                    that.batchDialogTableVisible = !that.batchDialogTableVisible;
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 批量编辑保存草稿数据
             */
            batchMergeDraft: function () {
                let that = this;
                this.load();
                postRequest("/system-config/system/resourcesSummaryEntity/mergeBatchDraft", that.resourcesPos).then(res => {
                    success(res.data.cnMessage);
                    that.closeLoad();
                    that.loadByPage(1, this.pageSize);
                    that.resourcesPos = [];
                    that.batchDialogTableVisible = !that.batchDialogTableVisible;
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 获取已选中数据的Id
             */
            getSelectedData() {
                let ids = [];
                this.multipleSelection.forEach(item => ids.push(item[this.getIdName()]));
                return ids;
            }
            ,
            /**
             * 加载指定数据
             */
            loadById: function (id, isView) {
                let that = this;
                that.load();
                getRequest(`/system-config/system/resourcesSummaryEntity/getById${isView ? "ForView" : ""}/` + id).then(res => {
                    that.ruleForm = res.data.data;
                    if (isView) {
                        that.viewVisible = !that.viewVisible;
                    }
                }).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 删除数据
             */
            delete: function () {
                let that = this;
                if (!this.multipleSelection || this.multipleSelection.length == 0) {
                    warning("请选择要删除的数据");
                    return;
                }
                confirm("确认需要删除选择的数据吗？", function () {
                    that.load();
                    postRequest("/system-config/system/resourcesSummaryEntity/batchDeleteByIdLogic", that.getSelectedData()).then(res => {
                        success(res.data.cnMessage);
                        that.multipleSelection = [];
                        that.closeLoad();
                        that.loadByPage(that.currentPage, that.pageSize);
                    }).catch(err => {
                        error(err)
                    }).finally(() => {
                        that.closeLoad();
                    })
                })

            }
            ,
            /**
             * 上传数据
             */
            upload: function (file, fileList) {

            }
            ,
            /**
             * 上传过程
             */
            uploadProcess: function (event, file, fileList) {
                this.load("数据导入中,请等待");
            }
            ,
            /**
             * 上传失败
             */
            uploadError: function (error, file, fileList) {
                this.closeLoad();
            }
            ,
            /**
             * 上传成功
             */
            uploadSuccess: function (response, file, fileList) {
                success(response.cnMessage);
                this.closeLoad();
                this.init();
            }
            ,
            /**
             * 导出所有数据
             */
            exportAll: function () {
                let that = this;
                that.load();
                download("/system-config/system/resourcesSummaryEntity/exportData", that.getSelectedData()).catch(err => {
                    error(err);
                }).finally(() => {
                    that.closeLoad();
                })
            }
            ,
            /**
             * 下载模板
             */
            downloadTemplate: function () {
                let that = this;
                download("/system-config/system/resourcesSummaryEntity/downloadTemplate", {}).catch(err => {
                    error(err);
                });
            }
        },
        created() {
            this.init();
        }
    }
</script>